﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
    
namespace NetworkTreeSample
{
    public class Item : INotifyPropertyChanged, IEnumerable<Item>
    {
        private List<Item> _childs = new List<Item>();

        public List<Item> SubNodes
        {
            get
            {
                return this._childs;
            }
            set
            {
                this._childs = value;
            }
        }

        public string Text { get; set; }

        public string Label
        {
            get
            {
                return Text;
            }
            set
            {
                Text = value;
            }
        }

        private bool _isExpanded;

        public bool IsExpanded
        {
            get
            {
                return this._isExpanded;
            }
            set
            {
                this._isExpanded = value;
                this.OnPropertyChanged("IsExpanded");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string p)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(p));
        }

        public IEnumerator<Item> GetEnumerator()
        {
            return SubNodes.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return SubNodes.GetEnumerator();
        }
    }
}
